<template>
  <div class="shopcar-container">

    <div v-if="this.$store.state.car.length != 0" class="goodslist">

      <!-- 商品列表区域 -->
      <div class="mui-card" v-for="(item,index) in this.$store.state.car" :key=index>
        <div class="mui-card-content">
          <div
            class="mui-card-content-inner">

              <mt-switch v-model="item.selected" @change="changeSelected(item.id,item.selected)"></mt-switch>

              <img :src="item.src"/>

              <div class="info">
                <h1>{{item.title}}</h1>
                <p>
                  <span class="price">￥{{item.price}}</span>
                  <numbox :initCount="$store.getters.getCountJson[item.id]" :goodsId="item.id"></numbox>
                  <a href="#" @click.prevent="remove(index)">删除</a>
                </p>
              </div>
            </div>
        </div>
      </div>

    </div>
    <div v-else class="goodslist">
        <h3>购物车竟然是空的。。。</h3>
    </div>

    <!-- 结算区域 -->
    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner jiesuan">
          <div class="left">
            <p>总计(不含运费)</p>
            <P>已勾选商品 <span class="red">{{$store.getters.getAllPrice.count}}</span> 件，总价 <span class="red">￥{{$store.getters.getAllPrice.price}}元</span></P>
          </div>
          <mt-button type="danger">去结算</mt-button>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
import numbox from '../subcomponents/shopcar_numbox.vue'
export default {
  methods:{
    changeSelected(id,selected){
      console.log(id,selected);
      var goodsinfo = {
        id:id,
        selected:selected
      };
      this.$store.commit("updateCount",goodsinfo);
    },
    remove(index){
      this.$store.commit("remove",index);
    }
  },
  components:{
    numbox
  }
};
</script>

<style lang="scss" scoped>
.shopcar-container{
  background-color: #eee;
  overflow: hidden;
  .goodslist{
    .mui-card-content-inner{
      display:flex;
      justify-content:space-between;
      align-items:center;
      img{
        width:60px;
        height:60px;
      }
      .info{
        display:flex;
        flex-direction: column;
        justify-content:space-between;
        h1{
          font-size: 13px;
          margin-bottom:10px;
        }
        p{
          font-size: 13px;
          margin:0;
        }
      }
    }
  }
  .jiesuan{
    display: flex;
    align-items: center;
    justify-content:space-between;
    .red{
      color: red;
      font-size:16px;
      font-weight: bold;
    }
  }
 
}
</style>